/*
 * Env.cpp
 *
 *  Created on: Jul 10, 2013
 *      Author: x
 */

#include "Env.h"
#include <string>
#include <fstream>
#include <iostream>
#include <sstream>

using namespace std;

namespace mcce {

Env::Env(): monte_seed(0),
			monte_temp(0.0),
			monte_flips(0),
			monte_nstart(0),
			monte_neq(0),
			monte_reduce(0.0),

			monte_runs(0),
			monte_niter(0),
			monte_trace(0),
			nstate_max(0),

			titr_ph0(0.0),
			titr_phd(0.0),
			titr_eh0(0.0),
			titr_ehd(0.0),
			titr_steps(0),

			big_pairwise(0.0),

			scale_vdw0(1.0),
			scale_vdw1(1.0),
			scale_vdw(1.0),
			scale_tor(1.0),
			scale_ele(1.0),
			scale_dsolv(1.0),

			mfe_cutoff(0.0),
			mfe_flag(0),
			mfe_point(0.0),

			ms_out(0)
{}

Env::~Env() {
}


void Env::loadFromRunprm(const string &fName) {
	string line;
	ifstream ifile(fName.c_str());
	while(getline(ifile, line)) {
		if (line.find("(MONTE_SEED)") != string::npos) {
			stringstream ss(line);
			ss >> monte_seed;
		}
		else if (line.find("(MONTE_T)") != string::npos) {
			stringstream ss(line);
			ss >> monte_temp;
		}
		else if (line.find("(MONTE_FLIPS)") != string::npos) {
			stringstream ss(line);
			ss >> monte_flips;
		}
		else if (line.find("(MONTE_NSTART)") != string::npos) {
			stringstream ss(line);
			ss >> monte_nstart;
		}
		else if (line.find("(MONTE_NEQ)") != string::npos) {
			stringstream ss(line);
			ss >> monte_neq;
		}
		else if (line.find("(MONTE_REDUCE)") != string::npos) {
			stringstream ss(line);
			ss >> monte_reduce;
		}
		else if (line.find("(MONTE_RUNS)") != string::npos) {
			stringstream ss(line);
			ss >> monte_runs;
		}
		else if (line.find("(MONTE_NITER)") != string::npos) {
			stringstream ss(line);
			ss >> monte_niter;
		}
		else if (line.find("(MONTE_TRACE)") != string::npos) {
			stringstream ss(line);
			ss >> monte_trace;
		}
		else if (line.find("(NSTATE_MAX)") != string::npos) {
			stringstream ss(line);
			ss >> nstate_max;
		}
		else if (line.find("(TITR_TYPE)") != string::npos) {
			stringstream ss(line);
			ss >> titr_type;
		}
		else if (line.find("(TITR_PH0)") != string::npos) {
			stringstream ss(line);
			ss >> titr_ph0;
		}
		else if (line.find("(TITR_PHD)") != string::npos) {
			stringstream ss(line);
			ss >> titr_phd;
		}
		else if (line.find("(TITR_EH0)") != string::npos) {
			stringstream ss(line);
			ss >> titr_eh0;
		}
		else if (line.find("(TITR_EHD)") != string::npos) {
			stringstream ss(line);
			ss >> titr_ehd;
		}
		else if (line.find("(TITR_STEPS)") != string::npos) {
			stringstream ss(line);
			ss >> titr_steps;
		}
		else if (line.find("(BIG_PAIRWISE)") != string::npos) {
			stringstream ss(line);
			ss >> big_pairwise;
		}
		else if (line.find("(SCALE_VDW0)") != string::npos) {
			stringstream ss(line);
			ss >> scale_vdw0;
		}
		else if (line.find("(SCALE_VDW1)") != string::npos) {
			stringstream ss(line);
			ss >> scale_vdw1;
		}
		else if (line.find("(SCALE_VDW)") != string::npos) {
			stringstream ss(line);
			ss >> scale_vdw;
		}
		else if (line.find("(SCALE_TOR)") != string::npos) {
			stringstream ss(line);
			ss >> scale_tor;
		}
		else if (line.find("(SCALE_ELE)") != string::npos) {
			stringstream ss(line);
			ss >> scale_ele;
		}
		else if (line.find("(SCALE_DSOLV)") != string::npos) {
			stringstream ss(line);
			ss >> scale_dsolv;
		}
		else if (line.find("(MFE_CUTOFF)") != string::npos) {
			stringstream ss(line);
			ss >> mfe_cutoff;
		}
		else if (line.find("(MFE_FLAG)") != string::npos) {
			stringstream ss(line);
			ss >> mfe_flag;
		}
		else if (line.find("(MFE_POINT)") != string::npos) {
			stringstream ss(line);
			ss >> mfe_point;
		}
		else if (line.find("(MS_OUT)") != string::npos) {
			stringstream ss(line);
			ss >> ms_out;
		}
	}
}

void Env::printEnv() {
	cout << "monte_seed:\t\t" << monte_seed << endl;
	cout << "monte_temp:\t\t" << monte_temp << endl;
	cout << "monte_flips:\t\t" << monte_flips << endl;
	cout << "monte_nstart:\t\t" << monte_nstart << endl;
	cout << "monte_neq:\t\t" << monte_neq << endl;
	cout << "monte_reduce:\t\t" << monte_reduce << endl;
	cout << "monte_runs:\t\t" << monte_runs << endl;
	cout << "monte_niter:\t\t" << monte_niter << endl;
	cout << "monte_trace:\t\t" << monte_trace << endl;
	cout << "nstate_max:\t\t" << nstate_max << endl;

	cout << "titr_ph0:\t\t" << titr_ph0 << endl;
	cout << "titr_phd:\t\t" << titr_phd << endl;
	cout << "titr_eh0:\t\t" << titr_eh0 << endl;
	cout << "titr_ehd:\t\t" << titr_ehd << endl;
	cout << "titr_steps:\t\t" << titr_steps << endl;

	cout << "big_pairwise:\t\t" << big_pairwise << endl;

	cout << "scale_vdw0:\t\t" << scale_vdw0 << endl;
	cout << "scale_vdw1:\t\t" << scale_vdw1 << endl;
	cout << "scale_vdw:\t\t" << scale_vdw << endl;
	cout << "scale_tor:\t\t" << scale_tor << endl;
	cout << "scale_ele:\t\t" << scale_ele << endl;
	cout << "scale_dsolv:\t\t" << scale_dsolv << endl;

	cout << "mfe_cutoff:\t\t" << mfe_cutoff << endl;
	cout << "mfe_flag:\t\t" << mfe_flag << endl;
	cout << "mfe_point:\t\t" << mfe_point << endl;
	cout << "ms_out:\t\t" << ms_out << endl;
}
} /* namespace mcce */
